package com.umeng.lx.Fragment;

import android.content.Context;
import android.util.Log;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.mymvp.view.ui.fragment.BaseMvpFramgent;
import com.umeng.lx.Adapter.MyAdapter;
import com.umeng.lx.Bean.Demo;
import com.umeng.lx.Bean.DemoList;
import com.umeng.lx.Molder.MainMolder;
import com.umeng.lx.Prensenter.MainPrensenter;
import com.umeng.lx.R;
import com.umeng.lx.View.MainView;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.List;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class AFragment extends BaseMvpFramgent<MainView, MainMolder, MainPrensenter> implements MainView {


    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    private MyAdapter myAdapter;

    @Override
    protected MainPrensenter createPresenter() {
        return new MainPrensenter();
    }

    @Override
    protected void initEvent() {
        mPerter.getData();
    }

    @Override
    protected int createLayoutId() {
        return R.layout.fragment_a;
    }

    @Override
    public void showList(List<Demo.ListBean> list) {
        Log.e("ths", "showList: "+list.size());
        banner.setImages(list).setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                Demo.ListBean bean= (Demo.ListBean) path;
                Glide.with(context).load(bean.getThumb()).into(imageView);
            }
        }).start();
    }

    @Override
    public void showError(String error, int code) {
        Log.e("ths", "showError: "+error+code);
    }

    @Override
    public void showRec(List<DemoList.ListDTO> beanList) {
        recyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
        myAdapter = new MyAdapter(beanList, context, R.layout.layout_item_1);
        recyclerview.setAdapter(myAdapter);
    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }
}
